package DynamicProgramingSeries;

public class ChangeSolution_518 {
    public int change(int amount, int[] coins) {
        // 完全背包问题
        // dp[j] = coins总和为j时的可能的coins的组合
        // dp[j] = dp[j] + dp[j-coins[i]]
        int[] dp = new int[amount + 1];

        dp[0] = 1;

        for (int j = 1; j <= amount; j++) {
            dp[j] = 0;
        }

        for (int i = 0; i < coins.length; i++) {
            for (int j = coins[i]; j <= amount; j++) {
                dp[j] = dp[j] + dp[j - coins[i]];
            }
        }
        return dp[amount] == 0 ? 0 : dp[amount];
    }
}
